package com.jxc.summer.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.jxc.summer.dao.UnitMapper;
import com.jxc.summer.service.UnitService;

@Service
public class UnitServiceImpl implements UnitService {

	@Autowired
	private UnitMapper unitMapper;
	
	@Transactional(propagation=Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED, readOnly=true)
	@Override
	public Map<String, Object> pageList(Map<String, Object> params) {
		List<Map<String, Object>> list = unitMapper.pageList(params);
		int count = unitMapper.pageListCount(params);
		// package result
		Map<String, Object> maps = new HashMap<String, Object>();
		maps.put("recordsTotal", count);		// 总记录数
		maps.put("recordsFiltered", count);	// 过滤后的总记录数
		maps.put("data", list); 
		return maps;
	}

	@Transactional(propagation=Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED)
	@Override
	public int addUnit(Map<String, Object> params) {
		int result = unitMapper.addUnit(params);
		return result;
	}

	@Transactional(propagation=Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED)
	@Override
	public int update(Map<String, Object> params) {
		int result = unitMapper.update(params);
		return result;
	}

	@Transactional(propagation=Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED)
	@Override
	public int delete(Map<String, Object> params) {
		int result = unitMapper.delete(params);
		return result;
	}

	@Override
	public List<String> getUnit(String companyCode) {
		return unitMapper.getUnit(companyCode);
	}

}
